#!/bin/bash

EXTERNALS_FOLDER="externals"

if [ ! -d ${EXTERNALS_FOLDER} ] ; then
mkdir externals
fi

DOWNLOAD="wget --continue"

BOOST_VERSION="1.46.1"
BOOST_FILE_NAME="boost_1_46_1"
BOOST_FILE="${BOOST_FILE_NAME}.tar.bz2"
BOOST_URL="http://sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/${BOOST_FILE}/download"

BZIP2_VERSION="1.0.6"
BZIP2_FILE_NAME="bzip2-${BZIP2_VERSION}"
BZIP2_FILE="${BZIP2_FILE_NAME}.tar.gz"
BZIP2_URL="http://bzip.org/${BZIP2_VERSION}/${BZIP2_FILE}"

ZLIB_FILE="zlib125.zip"
ZLIB_URL="http://zlib.net/${ZLIB_FILE}"

GTEST_FILE_NAME="gtest-1.6.0"
GTEST_FILE="${GTEST_FILE_NAME}.zip"
GTEST_URL="http://googletest.googlecode.com/files/${GTEST_FILE}"

${DOWNLOAD} ${BOOST_URL} -O "${EXTERNALS_FOLDER}/${BOOST_FILE}"
${DOWNLOAD} ${BZIP2_URL} -O "${EXTERNALS_FOLDER}/${BZIP2_FILE}"
${DOWNLOAD} ${ZLIB_URL} -O "${EXTERNALS_FOLDER}/${ZLIB_FILE}"
${DOWNLOAD} ${GTEST_URL} -O "${EXTERNALS_FOLDER}/${GTEST_FILE}"

################################################################
pushd ${EXTERNALS_FOLDER}

EXTRACT="7za x -y"

tar --bzip2 -xf ${BOOST_FILE}

tar --gzip -xf ${BZIP2_FILE}

${EXTRACT} ${ZLIB_FILE}
${EXTRACT} ${GTEST_FILE}

################################################################
mv ${BOOST_FILE_NAME} boost
pushd boost
./bootstrap.sh
popd

mv ${BZIP2_FILE_NAME} bzip2
mv zlib-1.2.5 zlib

mv ${GTEST_FILE_NAME} gtest
pushd gtest
./configure
popd

popd